#include "../Customer.h"
#include "CustomerService.h"
#include "CustomerRepository.h"

int validCustomer(struct Customer* customer)
{
    if(customer->id==0) return 1;
    if(customer->name==NULL) return 1;
    return 0;
}
int CustomerService_register(struct Customer* customer)
{
    if(validCustomer(customer)!=0) return 1;
    CustomerRepository_insert(customer);
    return 0;
}
int CustomerService_modify(struct Customer* customer)
{
    if(validCustomer(customer)!=0) return 1;
    CustomerRepository_update(customer);
    return 0;
}
int CustomerService_remove(long customerId)
{
    CustomerRepository_delete(customerId);
    return 0;
}
struct Customer* CustomerService_load(long customerId)
{
    return CustomerRepository_get(customerId);
}
int CustomerService_isExists(long customerId)
{
    struct Customer* customer = CustomerRepository_get(customerId);
    return customer==0;
}